 package com.gmrz.uaf.protocol.v1.schema;

 import com.gmrz.uaf.protocol.v1.json.UAFSchemaBuilder;
 import com.gmrz.util.Convert;
 import com.google.gson.Gson;
 import com.google.gson.annotations.Expose;
 import com.google.gson.annotations.SerializedName;
 import com.google.gson.reflect.TypeToken;

 public class HeaderAndFinalChallenge
 {
 
   @SerializedName("header")
   @Expose
   private OperationHeader operationHeader;
   private FinalChallengeParams finalChallengeParams;
 
   @SerializedName("fcParams")
   @Expose
   private String fcParamsBase64;
   private Base64URLEncoded<FinalChallengeParams> fcParams;

   public OperationHeader getOperationHeader()
   {
     return operationHeader;
   }
 
   public void setOperationHeader(OperationHeader operationHeader) {
     this.operationHeader = operationHeader;
   }
 
   public HeaderAndFinalChallenge withOperationHeader(OperationHeader operationHeader) {
     this.operationHeader = operationHeader;
     return this;
   }
 
   public String getFCPBase64() {
     return fcParamsBase64;
   }
 
   public FinalChallengeParams getFinalChallengeParams() {
     Gson gson = UAFSchemaBuilder.getGson();
     try {
       String fcpUFT8String = Convert.fromUtf8(Convert.fromBase64(fcParamsBase64));
       this.finalChallengeParams = gson.fromJson(fcpUFT8String, FinalChallengeParams.class);
     }
     catch (Exception e) {
       throw new RuntimeException("FinalChallengeParams is not UTF-8 encoded");
     }
     return this.finalChallengeParams;
   }
 
   public void setFinalChallengeParams(FinalChallengeParams finalChallengeParams) {
     this.finalChallengeParams = finalChallengeParams;
     this.fcParams = new Base64URLEncoded(finalChallengeParams);
     Gson gson = UAFSchemaBuilder.getGson();
     String fcpString = gson.toJson(finalChallengeParams, FinalChallengeParams.class);
     try {
       byte[] fcpStringBytes = Convert.toUtf8(fcpString);
       this.fcParamsBase64 = Convert.toBase64(fcpStringBytes);
     }
     catch (Exception e) {
       throw new RuntimeException("UTF-8 encoding is not supported.");
     }
   }
 
   public void setFinalChallengeParams(String fcpBase64) {
     TypeToken fcParams = new TypeToken() { };
     Gson gson = new Gson();
     this.finalChallengeParams = gson.fromJson(fcpBase64, fcParams.getType());
     this.fcParams = new Base64URLEncoded(this.finalChallengeParams);
   }
 
   public HeaderAndFinalChallenge withFinalChallengeParams(FinalChallengeParams finalChallengeParams) {
     setFinalChallengeParams(finalChallengeParams);
     return this;
   }
 }
